home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Effect library / Demo ƒ / Fades ƒ / Circle in fade.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-11  |  3.1 KB  |  105 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        Circle in fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8.  
  9. MSG Demo -- graphic effects demonstration program
  10. Copyright (C) 1992-4 Mark Pilgrim & Dave Blumenthal
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "msg timing.h"
  30.  
  31. #define    gap            4        /* difference between one radius and the next */
  32. #define CorrectTime 2
  33. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  34. #define theWindowWidth (boundsRect.right-boundsRect.left)
  35.  
  36. pascal short CircleInFade(Rect boundsRect, Pattern *thePattern);
  37.  
  38. /* Take a really big circle, then a slightly smaller circle (-gap), then
  39.    take the region in between them and copy that, then decrease the outer
  40.    circle radius by gap.  Thus: circle in, by successive donut-like copies. */
  41.  
  42. pascal short CircleInFade(Rect boundsRect, Pattern *thePattern)
  43. {
  44.     Rect            theRect;
  45.     int                cx, cy;
  46.     RgnHandle        curregion,lastregion,diffregion, boundsRgn, sectrgn;
  47.     Point            zeroPoint;
  48.     int                StartRadius;
  49.     
  50.     zeroPoint.h=boundsRect.left;
  51.     zeroPoint.v=boundsRect.top;
  52.  
  53.     cx = theWindowWidth / 2;
  54.     cy = theWindowHeight / 2;
  55.     
  56.     boundsRgn=NewRgn();
  57.     SetRectRgn(boundsRgn, boundsRect.left, boundsRect.top, boundsRect.right, boundsRect.bottom);
  58.     sectrgn=NewRgn();
  59.     lastregion=NewRgn();
  60.     StartRadius=0;
  61.     do
  62.     {
  63.         StartRadius+=2*gap;
  64.         theRect.left=cx-StartRadius;     /* circumscribing rectangle for outer circle */
  65.         theRect.right=cx+StartRadius;
  66.         theRect.top=cy-StartRadius;
  67.         theRect.bottom=cy+StartRadius;
  68.         OffsetRect(&theRect, boundsRect.left, boundsRect.top);
  69.         SetEmptyRgn(lastregion);
  70.         OpenRgn();
  71.             FrameOval(&theRect);        /* first circle */
  72.         CloseRgn(lastregion);
  73.     }
  74.     while (!PtInRgn(zeroPoint, lastregion));
  75.     
  76.     curregion=NewRgn();
  77.     diffregion=NewRgn();
  78.  
  79.     while (theRect.right-theRect.left>0)
  80.     {
  81.         StartTiming();
  82.         theRect.left+=gap;
  83.         theRect.right-=gap;
  84.         theRect.top+=gap;
  85.         theRect.bottom-=gap;
  86.         SetEmptyRgn(curregion);
  87.         OpenRgn();
  88.             FrameOval(&theRect);   /* inner circle */
  89.         CloseRgn(curregion);
  90.         DiffRgn(lastregion,curregion,diffregion);   /* donut we need */
  91.         SectRgn(diffregion, boundsRgn, sectrgn);
  92.         FillRgn(sectrgn, *thePattern);
  93.         CopyRgn(curregion,lastregion);    /* outer circle = inner circle */
  94.         TimeCorrection(CorrectTime);
  95.     }
  96.     
  97.     DisposeRgn(curregion);
  98.     DisposeRgn(lastregion);
  99.     DisposeRgn(diffregion);
  100.     DisposeRgn(boundsRgn);
  101.     DisposeRgn(sectrgn);
  102.     
  103.     return 0;
  104. }
  105.